package org.west.sky.frame.activiti.study.chapter15.demo03;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * author: chz
 * date: 2025/4/30
 * description:
 */
@Slf4j
public class ResultProcessor implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        //获取camel调用结果
        String camelCallResult = exchange.getIn().getBody(String.class);
        log.info("camel调用结果：{}", camelCallResult);
        Map<String,String> camelCallResultMap = JSON.parseObject(camelCallResult, Map.class);

        Map<String, String> resultMap = camelCallResultMap.entrySet().stream().filter(entry -> "country".equals(entry.getKey()) ||
                        "regionName".equals(entry.getKey()) || "city".equals(entry.getKey()) || "isp".equals(entry.getKey()))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

        exchange.getOut().setBody(resultMap, Map.class);
    }
}
